#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Solution
{
public:
    int jump(vector<int> &nums)
    {
        vector<int> dp(nums.size(), INT_MAX);
        dp[nums.size() - 1] = 0;
        for (int i = nums.size() - 2; i >= 0; i--)
        {
            int endIndex = std::clamp(i + nums[i] + 1, 0, static_cast<int>(nums.size()));
            dp[i] = *std::min_element(dp.begin() + i, dp.begin() + endIndex);
            dp[i] += 1;
        }
        return dp[0];
    }
};

int main()
{
    cout << "Code45" << endl;
    Solution s;
    vector<int> nums = {2, 3, 1, 1, 4};
    cout << s.jump(nums) << endl;
    return 0;
}